home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_06 / vancamp / tdexmpl.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-02  |  2.3 KB  |  80 lines

  1. // TDExmpl.hpp: Financial Market Example (LISTING 5)
  2. #ifndef TDEXMPL_HPP
  3. #define TDEXMPL_HPP
  4. #include "tdbuf.hpp"
  5.  
  6. // This class communicates with the database
  7. // (Note that cellType class must have SetValue()
  8. // and SetAttr() methods.)
  9. template <class cellType> class TableDataMarketBuf:
  10.         public TableDataBuffer<cellType>
  11. {
  12. public:
  13.     TableDataMarketBuf (TableData<cellType> *const
  14.             prev, const int nRows, const int nCols):
  15.             TableDataBuffer<cellType>
  16.             (prev, nRows, nCols)
  17.     {
  18.         // Put some dummy data in the table
  19.         // (Replace these with real database reads.)
  20.         assert (nRows == 4);
  21.         assert (nCols == 4);
  22.         for (int row = 0; row < GetNumRows(); row++)
  23.         {
  24.             for (int col=0; col < GetNumCols(); col++)
  25.             {
  26.                 RefCell(row, col).SetValue
  27.                         (row * 100 + col + 1);
  28.                 if (col > 2 || row < 2)
  29.                     RefCell(row, col).SetAttr
  30.                             (cellType::CT_PROTECTED);
  31.             }
  32.         }
  33.         strcpy (&RefRowHeading(0), "Sugar-Domest.");
  34.         strcpy (&RefRowHeading(1), "Cotton");
  35.         strcpy (&RefRowHeading(2), "Orange Juice");
  36.         strcpy (&RefRowHeading(3), "Brent Crude");
  37.         strcpy (&RefColHeading(0), "Open");
  38.         strcpy (&RefColHeading(1), "High");
  39.         strcpy (&RefColHeading(2), "Low");
  40.         strcpy (&RefColHeading(3), "Settle");
  41.  
  42.     }
  43.     // A real app would also provide a method to save
  44.     // updated data to the database.
  45. };
  46.  
  47. // A simple cell class to use in the table,
  48. // stores a float value & attribute per cell
  49. class ValAttrCell
  50. {
  51. public:
  52.     enum CellAttr // values can be OR'd
  53.     {
  54.         CT_NONE         = 0x00,
  55.         CT_PROTECTED    = 0x01,
  56.         CT_HIGHLIGHTED  = 0x02
  57.     };
  58.  
  59.     ValAttrCell (float value = 0.0, CellAttr attr
  60.             = CT_NONE): Value (value), Attr (attr)
  61.     { }
  62.  
  63.     void SetValue (float value)
  64.     { Value = value; }
  65.  
  66.     float GetValue (void) const
  67.     { return (Value); }
  68.  
  69.     void SetAttr (CellAttr attr)
  70.     { Attr = attr; }
  71.  
  72.     CellAttr GetAttr (void) const
  73.     { return (Attr); }
  74.  
  75. private:
  76.     float Value;   // value stored in cell
  77.     CellAttr Attr; // display (or other) attributes
  78. };
  79. #endif
  80.